Skip to content

HTML API: Escape syntax characters in RCDATA - #13327

Closed
dmsnell wants to merge 2 commits into
WordPress:trunkfrom
dmsnell:html-api/escape-rcdata
Closed

HTML API: Escape syntax characters in RCDATA#13327
dmsnell wants to merge 2 commits into
WordPress:trunkfrom
dmsnell:html-api/escape-rcdata

Conversation

@dmsnell

@dmsnell dmsnell commented Aug 31, 2026

Copy link
Copy Markdown
Member

Trac ticket: Core-65984

Status

  • Add some tests to demonstrate behavior.

Description

Characters in TITLE and TEXTAREA aren’t required to be escaped, but doing so might prevent downstream parsers from mis-parsing content inside of these elements as markup, when in fact they are plaintext.

This patch escapes the content by default to prevent such a scenario.

@dmsnell
dmsnell force-pushed the html-api/escape-rcdata branch 2 times, most recently from c3de662 to 686dc5e Compare August 31, 2026 05:02
@dmsnell
dmsnell requested review from sirreal and westonruter August 31, 2026 05:03
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php

@sirreal sirreal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably an improvement overall for anything inspecting HTML downstream.

Assume HTML like: <title><foo>&lt;bar&gt;</title>

There are two obvious ways to mis-parse this:

  • <foo> treated as a start tag (it's the text <foo>)
  • &lt;bar&gt; not decoded (it's the text <bar>).

This change would eliminate the first category <foo>, while leaving the second category &lt;bar&gt; exactly the same. The tradeoff here is that naive parsers are more likely to confuse the text <foo> for an element, and if they don't correctly handle decoding… well that would already be broken.

I'm in favor of this, it's perfectly valid and correct HTML and simplifies the surface area of HTML trivia that needs to be correctly implemented downstream.


In some related CSS work, I made a similar decision. It's best to remove possibly confusing syntax characters entirely where escaping is possible.

Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
@dmsnell
dmsnell force-pushed the html-api/escape-rcdata branch from 686dc5e to a772966 Compare August 31, 2026 22:26
@dmsnell

dmsnell commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

I’ve added the comments, updated the code, and added tests verifying the behavior.

Assuming those pass I will merge this!

@dmsnell
dmsnell marked this pull request as ready for review August 31, 2026 22:30
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dmsnell, westonruter, jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@dmsnell
dmsnell force-pushed the html-api/escape-rcdata branch 2 times, most recently from 2ea5d13 to 9b177f0 Compare August 31, 2026 22:54
@dmsnell
dmsnell force-pushed the html-api/escape-rcdata branch from 9b177f0 to d4ebb79 Compare August 31, 2026 23:17
pento pushed a commit that referenced this pull request Sep 1, 2026
Characters in TITLE and TEXTAREA aren’t required to be escaped, but doing so might prevent downstream parsers from mis-parsing content inside of these elements as markup, when in fact they are plaintext.

This patch escapes the content by default to prevent such a scenario.

Developed in: #13327
Discussed in: https://core.trac.wordpress.org/ticket/65984

Props dmsnell, jonsurrell, westonruter.
See #65984.


git-svn-id: https://develop.svn.wordpress.org/trunk@63418 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Sep 1, 2026
Characters in TITLE and TEXTAREA aren’t required to be escaped, but doing so might prevent downstream parsers from mis-parsing content inside of these elements as markup, when in fact they are plaintext.

This patch escapes the content by default to prevent such a scenario.

Developed in: WordPress/wordpress-develop#13327
Discussed in: https://core.trac.wordpress.org/ticket/65984

Props dmsnell, jonsurrell, westonruter.
See #65984.

Built from https://develop.svn.wordpress.org/trunk@63418


git-svn-id: http://core.svn.wordpress.org/trunk@62610 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@dmsnell

dmsnell commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Merged in [63418]
049287a

@dmsnell dmsnell closed this Sep 1, 2026
@dmsnell
dmsnell deleted the html-api/escape-rcdata branch September 1, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants